/* ************************************************************************

   Copyright:
     2008 openWorks

   License:
     LGPL: http://www.gnu.org/licenses/lgpl.html
     See the LICENSE file in the project's top-level directory for details.

   Authors:
     * Martín Alejandro Paz

************************************************************************ */

/**
* 
* *Ejemplo:*
*
* <pre class='javascript'>
*  var structure =
*  [
*    {name:'tab1', value:'Tab 1', icon:'icon.png'},
*    {name:'tab2', value:'Tab 2'}
*  ]
*  var tabs = new qx.ui.form.ow.Tabs(structure, 400, 200);
*  tabs.addToTab("tab1", new qx.ui.form.ow.TextField("Prueba Tab"), {left:10, top:10});
*  </pre>
*/
qx.Class.define("qx.ui.form.ow.Tabs",
{
	extend : qx.ui.container.Composite,
	construct : function (width, height,structure)
	{
		this.base(arguments);

		this.setLayout(new qx.ui.layout.Canvas);

		this._tabView = new qx.ui.tabview.TabView();
		
		if (width != null)
		{
			this._tabView.setWidth(width);
		}
		else
		{
			this._tabView.setWidth(360);
		}

		if (height != null)
		{
			this._tabView.setHeight(height);
		}
		else
		{
			this._tabView.setHeight(200);
		}

		this._tabsPages = [];
		for (r in structure)
		{
			this.addTab(structure[r]);
		}
		this.add(this._tabView, {left:0, top:0});
	},
	members :
	{
		_tabView : null,
		_tabsPages : null,
		addTab : function (rowStructure)
		{
			if (rowStructure.value != null)
			{
				this._tabsPages[rowStructure.name] = new qx.ui.tabview.Page(rowStructure.value, rowStructure.icon);
			}
			else
			{
				this._tabsPages[rowStructure.name] = new qx.ui.tabview.Page(rowStructure.name, rowStructure.icon);
			}
			this._tabsPages[rowStructure.name].setLayout(new qx.ui.layout.Basic());
			this._tabView.add(this._tabsPages[rowStructure.name]);
		},
		addToTab : function (name, widget, position)
		{
			if ((name != null) && (widget != null))
			{
				this._tabsPages[name].add(widget, position);
			}
		},
		getContentTab : function (name)
		{
			return this._tabsPages[name];
		},
		setEnabledTab : function (name, enabled)
		{
			this._tabsPages[name].setEnabled(enabled);
		},
		getTabView : function(){
			return this._tabView;
		}
	}
});
